const { subjectsModel } = require('../models/subjectsModel')
const { classesModel } = require('../models/classesModel');

module.exports.createSubjects = async function (req, res) {
    const data = req.body;
    const result = await subjectsModel.create(data);
    
    // 将当前图片从 temp 移动到 images
    // 将 temp 文件删掉

    res.send({
        message: '专业新增成功',
        code: 1,
        result
    })
}

module.exports.getSubjects = async function (req, res) {
    const { currentPage, pageSize } = req.query;
    // 总条数
    const total = await subjectsModel.countDocuments();
    // 总页数
    let pages = 1;
    if(pageSize) {
        pages = Math.ceil(total / pageSize);
    }

    // 专业数据
    const result = await subjectsModel.find().limit(pageSize - 0).skip((currentPage - 1) * pageSize);
    
    res.send({
        code: 1,
        message: '专业数据获取成功',
        result: { total, pages, rows: result }
    })
}

